package huriezy.quickcontacts.models;

import huriezy.quickcontacts.models.interfaces.IContactManager;
import huriezy.quickcontacts.models.interfaces.ILocationManager;
import huriezy.quickcontacts.models.interfaces.IPictureManager;
import huriezy.quickcontacts.models.managers.ContactLocationManager;
import huriezy.quickcontacts.models.managers.ContactManager;
import huriezy.quickcontacts.models.managers.ContactPictureManager;
import android.content.Context;

public class ContactController {

	private static ContactController	instance;

	private ILocationManager			lastLocationManager;
	private IContactManager				lastContactManager;
	private IPictureManager				lastIPictureManager;

	// This field is used to verify if, after initialization, the requested
	// manager is asked from a component relative to the donate context.
	private Context						relativeContext;

	private ContactController() {

		// TODO adapt selected managers in function of the current version,
		// configuration and parameters.

	}

	public static ContactController getInstance() {
		if (instance == null) {
			instance = new ContactController();
		}
		return instance;
	}

	public void initManagers(Context context) {
		if (context != null) {
			relativeContext = context;
			lastLocationManager = new ContactLocationManager(context);
			lastContactManager = new ContactManager(context);
			lastIPictureManager = new ContactPictureManager(context);
		}
	}

	public ILocationManager getLocationManager(Context context) {
		ILocationManager result = null;
		if (relativeContext != null && relativeContext.equals(context)) {
			result = lastLocationManager;
		}
		return result;
	}

	public IContactManager getContactManager(Context context) {
		IContactManager result = null;
		if (relativeContext != null && relativeContext.equals(context)) {
			result = lastContactManager;
		}
		return result;
	}

	public IPictureManager getPictureManager(Context context) {
		IPictureManager result = null;
		if (relativeContext != null && relativeContext.equals(context)) {
			result = lastIPictureManager;
		}
		return result;
	}
}
